package Contest.week93;

import java.util.Arrays;

public class _869_ReorderedPowerof2 {
    //use string compare
    public boolean reorderedPowerOf2(int N) {
        int power = 1;
        StringBuffer sb = new StringBuffer();
        char[] n = String.valueOf(N).toCharArray();
        Arrays.sort(n);
        for (int i = n.length-1; i >=0; i--) {
            sb.append(n[i]);
        }
        System.out.println(sb.toString());
        while (power <= Integer.parseInt(sb.toString())) {
            char[] p = String.valueOf(power).toCharArray();
            if (p.length == n.length) {
                Arrays.sort(p);
                boolean check = false;
                for (int i = 0; i < p.length; i++) {
                    if (p[i] != n[i]) {
                        check = true;
                        break;
                    }
                }
                if (!check) {
                    return true;
                }
            }
            power *= 2;
        }
        return false;
    }

}
